﻿using System;
using System.Collections.Generic;
using System.Linq;
using nkstdgia.common.DuongKhaoSat;

namespace nkstdgia
{
    public partial class SuggestionHelper : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["type"] != null)
            {
                switch (Request.QueryString["type"].ToString())
                {
                    case "duongsuggestion":
                        if (Request.QueryString["pid"] != null && Request.QueryString["qid"] != null && Request.QueryString["keyword"] != null)
                        {
                            string qid = Request.QueryString["qid"].ToString();
                            string pid = Request.QueryString["pid"].ToString();
                            string keyword = Request.QueryString["keyword"].ToString().ToLower();

                            DuongKhaoSatDataService _TagAccess = new DuongKhaoSatDataService();
                            List<TenDuongKhaoSatInfo> listtag = _TagAccess.searchDuong(int.Parse(qid), int.Parse(pid));
                            List<string> listStr = (from c in listtag
                                                    where c.DUONG.ToLower().Contains(keyword)
                                                    select c.DUONG).ToList();
                            string str = "";
                            foreach (string item in listStr)
                            {
                                str += item + ",";
                            }
                            if (str.Length > 0)
                            {
                                str = str.Remove(str.Length - 1);
                            }
                            Response.Write(str);
                        }
                        break;
                    case "doanduongsuggestion":
                        if (Request.QueryString["pid"] != null && Request.QueryString["qid"] != null && Request.QueryString["keyword"] != null)
                        {
                            string qid = Request.QueryString["qid"].ToString();
                            string pid = Request.QueryString["pid"].ToString();
                            string keyword = Request.QueryString["keyword"].ToString().ToLower();

                            DuongKhaoSatDataService _TagAccess = new DuongKhaoSatDataService();
                            List<DuongKhaoSatInfo> listtag = _TagAccess.searchDoanDuong(int.Parse(qid), int.Parse(pid));
                            List<string> listStr = (from c in listtag
                                                    where c.DOAN_DUONG.ToLower().Contains(keyword)
                                                    select c.DOAN_DUONG).ToList();
                            string str = "";
                            foreach (string item in listStr)
                            {
                                str += item + ",";
                            }
                            if (str.Length > 0)
                            {
                                str = str.Remove(str.Length - 1);
                            }
                            Response.Write(str);
                        }
                        break;
                    default:
                        Response.Write("{|noresult|}");
                        break;
                }
            }
        }
    }
}
